"use client";

import type React from "react";
import { Analytics } from "@vercel/analytics/next";
import { Suspense } from "react";
import { usePathname } from "next/navigation";
import { AuthProvider } from "@/lib/auth-context";
import { SiteHeader } from "@/components/site-header";
import { MenuProvider } from "@/contexts/MenuContext";
import { QueryProvider } from "@/contexts/QueryProvider";

export default function ClientLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const pathname = usePathname();
  const sidebarLayoutPaths = ["/ai-tools", "/kason-nav", "/news", "/amazing-website"];
  const hasSidebar = sidebarLayoutPaths.some((path) =>
    pathname.startsWith(path)
  );

  return (
    <AuthProvider>
      <QueryProvider>
        <MenuProvider>
          <div className="flex flex-col h-screen">
            <SiteHeader />
            {hasSidebar ? (
              <div className="flex flex-1 overflow-hidden overflow-hidden">{children}</div>
            ) : (
              <main className="flex-1 overflow-y-auto">{children}</main>
            )}
          </div>
          <Suspense fallback={null}>
            <Analytics />
          </Suspense>
        </MenuProvider>
      </QueryProvider>
    </AuthProvider>
  );
}
